#include <iostream>

using namespace std;
// 循环队列
template<class type, int volume>
class RoundQueue {
private:
    type data[volume];
    int head;//[0,volumn)
    int tail;//[0,volumn)
    int _volume;

public:

    RoundQueue<type, volume>() : head(0), tail(0),_volume(volume) {};

    constexpr int size() const {
        return volume;
    };

    bool empty() const {
        return head == tail;
    };

    void push(const type &obj) {
        data[head] = obj;
        head = (head + 1) % volume;
        if (head == tail) {
            tail = (tail + 1) % volume;
        }
    };

    type pop() {
        if (empty()) return false;
        type &obj = data[tail];
        tail = (tail + 1) % volume;
        return obj;
    };

    type &operator[](int idx) {
        while (tail + idx < 0) idx += volume;
        return data[(tail + idx) % volume];
    };

    //geshu
    type length(){
        if(head>=tail) return head-tail;
        else return _volume+1-(tail-head);

    }

    double mean(){
        int len=length();
        type plus = 0;
        for(int i = 0;i<len;i++){
            plus+=(*this)[tail+i];
        }
        cout<<len<<" "<<plus<<endl;
        return (double)plus/(double)len;
    }
};

int main() {
    RoundQueue<int,10> queue;
//    for(int i=0;i<3*queue._volume;i++) {
//        queue.push(queue.head);
//        for (int j = 0; j < queue._volume; j++) {
//            if(j==queue.head) cout << j << ": " << queue.data[j] << " head   ";
//            else if(j==queue.tail) cout << j << ": " << queue.data[j] << " tail   ";
//            else cout << j << ": " << queue.data[j] << "        ";
//        }
//        cout<<endl;
        cout<<"[mean]:"<<queue.mean()<<endl;
//        for (int j = 0; j < queue._volume; j++) {
//            cout << -j << ": " << queue[-j] << "   ";
//        }
//        cout<<endl;
    }
}
